<style>
</style>
<script src="/public/js/ajax_file_upload.js" type="text/javascript"></script>
<script type="text/javascript" src="/public/js/jquery.ui.widget.js" charset="utf-8"></script>
<script type="text/javascript" src="/public/js/jquery.fileupload.js" charset="utf-8"></script>
<div class="upload-con" id="uploader" style="display:none;overflow:auto;height:350px;width:185px;">
	<div class="js-file-msg"></div>
	<div class="upload-pmgressbar js-file-loading"></div>
	<div class="upload-txt"><span>支持Jpg、Png格式，大小不超过1024KB的图片上传；浏览文件时可以按住ctrl或shift键多选。</span></div>
</div>
<script type="text/javascript">
$(function() {
	//鼠标触及区域li改变class
	var group_id = $("#group_id").val();
	var dataAlbum = {
		"group_id" : group_id,
		"type" : "1,2,3,4",
		'file_path' : 'goods/'
	};
	// ajax 上传图片
	var upload_num = 0; // 上传图片成功数量
	$('#fileupload').fileupload({
		url: "{:url('upload/photoalbumupload')}",
		dataType: 'json',
		formData:dataAlbum,
		add: function (e,data) {
			//显示上传图片框
			if($("#uploader").is(":hidden")){
				$("#uploader").show();
			}
			$.each(data.files, function (index, file) {
				$('<div data-name="' + file.name + '"><p>'+ file.name +'</p><p class="loading"></p></div>').appendTo('.js-file-loading');
			});
			data.submit();
		},
		done: function (e,data) {
			var param = data.result;
			if(param['code'] == 1)
			{
                $this = $('div[data-name="' + param.origin_file_name + '"]');
                $this.fadeOut(3000, function(){
                    $(this).remove();
                    if ($('.js-file-loading').html() == '') {
                        $("#uploader").hide();
                        window.location.reload();
                    }
                });
                if(param.state > 0){
                    upload_num++;
                    $('.js-file-msg').html('<i class="icon-ok-sign">'+'</i>'+'成功上传'+upload_num+'张图片');
                } else {
                    layer.msg(param.message, {icon: 5, time: 1000});
                    $('.loading').html(param.message).removeClass('loading');
                }
			}
			else
			{
                layer.msg(param.message, {icon: 5, time: 1000});
                $('.loading').html(param.message).removeClass('loading');
			}
		}
	});
});
</script>